﻿using CRM.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System.IO;
using Microsoft.AspNetCore.Http;

namespace CRM.Controllers
{
    public class UploadController : BaseController
    {
        private UploadService _UploadService;
        public UploadController(UploadService uploadService)
        {
            _UploadService = uploadService;
        }

        /// <summary>
        /// OEM 单图片上传
        /// </summary>
        /// <param name="formFile"></param>
        /// <returns></returns>
        [HttpPost("[Action]")]
        public async Task<ResultStruct> UploadOemImg([FromForm] IFormCollection FormFile) {
            var FileFolder = Path.Combine("", "temporary/oem/");
            UploadService.ResultObject ret = await _UploadService.UploadSingleImg(FileFolder, FormFile);
            if (ret.State) {
                return Success(ret.Data);
            }
            return Error(ret.Data);
        }
        
        /// <summary>
        /// 买家数据 个人发布 图片上传
        /// </summary>
        /// <param name="formFile"></param>
        /// <returns></returns>
        [HttpPost("[Action]")]
        public async Task<ResultStruct> UploadBuyerDataImg([FromForm] IFormCollection FormFile) {
            var FileFolder = Path.Combine("", "temporary/buyerData/");
            UploadService.ResultObject ret = await _UploadService.UploadSingleImg(FileFolder, FormFile);
            if (ret.State) {
                return Success(ret.Data);
            }
            return Error(ret.Data);
        }
    }
}
